<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="关联账号userId" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入关联账号userId"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工地" prop="constructionSiteId">
        <el-input
          v-model="queryParams.constructionSiteId"
          placeholder="请输入工地"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="土场" prop="soilFieldId">
        <el-input
          v-model="queryParams.soilFieldId"
          placeholder="请输入土场"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业" prop="enterpriseInfoId">
        <el-input
          v-model="queryParams.enterpriseInfoId"
          placeholder="请输入企业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申报有效期开始日期-这个由城管审核的时候赋予" prop="startDate">
        <el-input
          v-model="queryParams.startDate"
          placeholder="请输入申报有效期开始日期-这个由城管审核的时候赋予"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申报有效期结束日期-这个由城管审核的时候赋予" prop="endDate">
        <el-input
          v-model="queryParams.endDate"
          placeholder="请输入申报有效期结束日期-这个由城管审核的时候赋予"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件编号" prop="certNum">
        <el-input
          v-model="queryParams.certNum"
          placeholder="请输入证件编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工地负责人" prop="leader">
        <el-input
          v-model="queryParams.leader"
          placeholder="请输入工地负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人联系电话" prop="leaderPhone">
        <el-input
          v-model="queryParams.leaderPhone"
          placeholder="请输入负责人联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工地名称" prop="constructionSiteName">
        <el-input
          v-model="queryParams.constructionSiteName"
          placeholder="请输入工地名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="土场名称" prop="soilSiteInfoName">
        <el-input
          v-model="queryParams.soilSiteInfoName"
          placeholder="请输入土场名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线路名称" prop="lineName">
        <el-input
          v-model="queryParams.lineName"
          placeholder="请输入线路名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线路准行时间段" prop="linePtd">
        <el-input
          v-model="queryParams.linePtd"
          placeholder="请输入线路准行时间段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['modules:solieInfo1:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['modules:solieInfo1:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['modules:solieInfo1:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['modules:solieInfo1:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="关联账号userId" align="center" prop="userId" />
      <el-table-column label="工地" align="center" prop="constructionSiteId" />
      <el-table-column label="土场" align="center" prop="soilFieldId" />
      <el-table-column label="线路" align="center" prop="lineId" />
      <el-table-column label="企业" align="center" prop="enterpriseInfoId" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="车辆-必填" align="center" prop="vehicle" />
      <el-table-column label="借调车辆" align="center" prop="borrowedVehicle" />
      <el-table-column label="申报有效期开始日期-这个由城管审核的时候赋予" align="center" prop="startDate" />
      <el-table-column label="申报有效期结束日期-这个由城管审核的时候赋予" align="center" prop="endDate" />
      <el-table-column label="渣土处置证-附件-必填" align="center" prop="wasteDisposalProof" />
      <el-table-column label="现场验收表" align="center" prop="onSiteAcceptanceForm" />
      <el-table-column label="要图证明-附件-必填" align="center" prop="drawingProof" />
      <el-table-column label="借车证明-附件" align="center" prop="borrowedProof" />
      <el-table-column label="夜间出土证明-附件" align="center" prop="nightSoilProof" />
      <el-table-column label="证件编号" align="center" prop="certNum" />
      <el-table-column label="下一步可审核人员" align="center" prop="nextReviewUserIds" />
      <el-table-column label="已审人员名称" align="center" prop="auditedUserNames" />
      <el-table-column label="已审人员" align="center" prop="auditedUserIds" />
      <el-table-column label="工地负责人" align="center" prop="leader" />
      <el-table-column label="负责人联系电话" align="center" prop="leaderPhone" />
      <el-table-column label="工地名称" align="center" prop="constructionSiteName" />
      <el-table-column label="土场名称" align="center" prop="soilSiteInfoName" />
      <el-table-column label="线路名称" align="center" prop="lineName" />
      <el-table-column label="线路途径信息" align="center" prop="lineContent" />
      <el-table-column label="线路准行时间段" align="center" prop="linePtd" />
      <el-table-column label="申报车辆车牌号" align="center" prop="plates" />
      <el-table-column label="借调车辆车牌号" align="center" prop="borrowPlates" />
      <el-table-column label="扩展位" align="center" prop="exts" />
      <el-table-column label="附件扩展位" align="center" prop="fileExts" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['modules:solieInfo1:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['modules:solieInfo1:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改证件办理信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="关联账号userId" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入关联账号userId" />
        </el-form-item>
        <el-form-item label="工地" prop="constructionSiteId">
          <el-input v-model="form.constructionSiteId" placeholder="请输入工地" />
        </el-form-item>
        <el-form-item label="土场" prop="soilFieldId">
          <el-input v-model="form.soilFieldId" placeholder="请输入土场" />
        </el-form-item>
        <el-form-item label="线路" prop="lineId">
          <el-input v-model="form.lineId" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="企业" prop="enterpriseInfoId">
          <el-input v-model="form.enterpriseInfoId" placeholder="请输入企业" />
        </el-form-item>
        <el-form-item label="车辆-必填" prop="vehicle">
          <el-input v-model="form.vehicle" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="借调车辆" prop="borrowedVehicle">
          <el-input v-model="form.borrowedVehicle" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="申报有效期开始日期-这个由城管审核的时候赋予" prop="startDate">
          <el-input v-model="form.startDate" placeholder="请输入申报有效期开始日期-这个由城管审核的时候赋予" />
        </el-form-item>
        <el-form-item label="申报有效期结束日期-这个由城管审核的时候赋予" prop="endDate">
          <el-input v-model="form.endDate" placeholder="请输入申报有效期结束日期-这个由城管审核的时候赋予" />
        </el-form-item>
        <el-form-item label="渣土处置证-附件-必填" prop="wasteDisposalProof">
          <el-input v-model="form.wasteDisposalProof" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="现场验收表" prop="onSiteAcceptanceForm">
          <el-input v-model="form.onSiteAcceptanceForm" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="要图证明-附件-必填" prop="drawingProof">
          <el-input v-model="form.drawingProof" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="借车证明-附件" prop="borrowedProof">
          <el-input v-model="form.borrowedProof" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="夜间出土证明-附件" prop="nightSoilProof">
          <el-input v-model="form.nightSoilProof" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="证件编号" prop="certNum">
          <el-input v-model="form.certNum" placeholder="请输入证件编号" />
        </el-form-item>
        <el-form-item label="下一步可审核人员" prop="nextReviewUserIds">
          <el-input v-model="form.nextReviewUserIds" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="已审人员名称" prop="auditedUserNames">
          <el-input v-model="form.auditedUserNames" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="已审人员" prop="auditedUserIds">
          <el-input v-model="form.auditedUserIds" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="工地负责人" prop="leader">
          <el-input v-model="form.leader" placeholder="请输入工地负责人" />
        </el-form-item>
        <el-form-item label="负责人联系电话" prop="leaderPhone">
          <el-input v-model="form.leaderPhone" placeholder="请输入负责人联系电话" />
        </el-form-item>
        <el-form-item label="工地名称" prop="constructionSiteName">
          <el-input v-model="form.constructionSiteName" placeholder="请输入工地名称" />
        </el-form-item>
        <el-form-item label="土场名称" prop="soilSiteInfoName">
          <el-input v-model="form.soilSiteInfoName" placeholder="请输入土场名称" />
        </el-form-item>
        <el-form-item label="线路名称" prop="lineName">
          <el-input v-model="form.lineName" placeholder="请输入线路名称" />
        </el-form-item>
        <el-form-item label="线路途径信息">
          <editor v-model="form.lineContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="线路准行时间段" prop="linePtd">
          <el-input v-model="form.linePtd" placeholder="请输入线路准行时间段" />
        </el-form-item>
        <el-form-item label="申报车辆车牌号" prop="plates">
          <el-input v-model="form.plates" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="借调车辆车牌号" prop="borrowPlates">
          <el-input v-model="form.borrowPlates" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="扩展位" prop="exts">
          <el-input v-model="form.exts" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="附件扩展位" prop="fileExts">
          <el-input v-model="form.fileExts" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/modules/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 证件办理信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        constructionSiteId: null,
        soilFieldId: null,
        lineId: null,
        enterpriseInfoId: null,
        status: null,
        vehicle: null,
        borrowedVehicle: null,
        startDate: null,
        endDate: null,
        wasteDisposalProof: null,
        onSiteAcceptanceForm: null,
        drawingProof: null,
        borrowedProof: null,
        nightSoilProof: null,
        certNum: null,
        nextReviewUserIds: null,
        auditedUserNames: null,
        auditedUserIds: null,
        leader: null,
        leaderPhone: null,
        constructionSiteName: null,
        soilSiteInfoName: null,
        lineName: null,
        lineContent: null,
        linePtd: null,
        plates: null,
        borrowPlates: null,
        exts: null,
        fileExts: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "关联账号userId不能为空", trigger: "blur" }
        ],
        constructionSiteId: [
          { required: true, message: "工地不能为空", trigger: "blur" }
        ],
        soilFieldId: [
          { required: true, message: "土场不能为空", trigger: "blur" }
        ],
        lineId: [
          { required: true, message: "线路不能为空", trigger: "blur" }
        ],
        enterpriseInfoId: [
          { required: true, message: "企业不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "change" }
        ],
        vehicle: [
          { required: true, message: "车辆-必填不能为空", trigger: "blur" }
        ],
        wasteDisposalProof: [
          { required: true, message: "渣土处置证-附件-必填不能为空", trigger: "blur" }
        ],
        onSiteAcceptanceForm: [
          { required: true, message: "现场验收表不能为空", trigger: "blur" }
        ],
        drawingProof: [
          { required: true, message: "要图证明-附件-必填不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询证件办理信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        constructionSiteId: null,
        soilFieldId: null,
        lineId: null,
        enterpriseInfoId: null,
        status: null,
        vehicle: null,
        borrowedVehicle: null,
        startDate: null,
        endDate: null,
        wasteDisposalProof: null,
        onSiteAcceptanceForm: null,
        drawingProof: null,
        borrowedProof: null,
        nightSoilProof: null,
        certNum: null,
        nextReviewUserIds: null,
        auditedUserNames: null,
        auditedUserIds: null,
        leader: null,
        leaderPhone: null,
        constructionSiteName: null,
        soilSiteInfoName: null,
        lineName: null,
        lineContent: null,
        linePtd: null,
        plates: null,
        borrowPlates: null,
        exts: null,
        fileExts: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加证件办理信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改证件办理信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除证件办理信息编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('modules/solieInfo1/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
